package it.unibz.easytravel.itemlist;

import java.util.Vector;

public class Synchronizer {
	//Synchronize two Item lists
	public static final ItemList synchronize (ItemList userList, ItemList serverList)  {
		int i, j;
		Item userItem, serverItem;
		for(i = 0; i < userList.size(); i++) {
			userItem = (Item)userList.elementAt(i);
			if (userItem.sharedItem) {
				for (j = 0; j < serverList.size(); j++) {
					serverItem = (Item)serverList.elementAt(j);
					if (serverItem.name == userItem.name) {
						if (serverItem.taken || userItem.taken) {
							userItem.taken = true;
							serverItem.taken = true;
						}
					}
				}
			}
		}
		return userList;
	}
	
	public static final ItemList syncronizeAll (Vector ItemLists){
		return (ItemList) ItemLists.elementAt(0);
	}
}
